
#ifndef __ACTORS_DB_H
#define __ACTORS_DB_H

#include <stdint.h>
#include <vector>
#include "../net/netgeneral.h"
#include <apr_network_io.h>
#include "SQLiteDB.h"

class ActorsDB : public SQLiteDB
{
   public:
      ActorsDB(const char *filename) : SQLiteDB(filename, 1) { CreateTablesIfNecessary(); }
      ~ActorsDB();
      std::vector<char *> *GetUserWorkDataState(const char *name, const char *work_store_name, apr_pool_t *mp);
      std::vector<char *> *GetUserState(const char *name, apr_pool_t *mp);
      std::vector<char *> *GetReadyResults(const char *uuid);
      void AddUserToActors(const char *name, const char *date, int64_t credit, apr_size_t quotabytes);
      void AddWorkStore(const char *hash, const char *username, int blocks, int blocksize, const char *uncopyhash, const char *workdata);
      void AddOrReplaceDelegateKey(const char *delegate_key_uuid, const char *owner);
      int IsWorkStoreStarted(const char *uuid);
      void WorkStoreSetCancelled(const char *uuid);
      void WorkStoreSetStarted(const char *uuid);
      void WorkStoreSetUsable(const char *uuid);
      std::vector<char *> *ViewWorkStoresOwned(const char *owner);
      std::vector<char *> *ViewWorkStoreByUUID(const char *uuid);
      int GrantUUIDPermission(const char *uuid1, const char *uuid2);
      char *LookupUltimateUser(const char *uuid);
      int ModifyUserQuota(const char *username, apr_off_t modifier);
      int ReplaceUserQuota(const char *username, apr_size_t newquota);
      apr_off_t GetUserQuota(const char *username);
      void AddComputeSession(const char *uuid, int durationSeconds, apr_sockaddr_t *cliaddr, const char *capabilities);
      std::vector<char *> *AtomicGetWork(const char *realowner, int tmax_given, const char *forcejob);
      void SetCompletedWork(const char *workname);
      void CleanExpiredWork();
      void CreateWorkFromFileStoreID(const char *filestoreid, const char *clusterprefs, int maxDuration, int instances);
      int GetInstancesFromWorkStore(const char *uuid);
      int QuietlyVerifyUUIDIsCompute(const char *uuid);
      int VerifyUUIDIsCompute(const char *uuid);
      int VerifyUUIDIsCompute(const char *uuid, int suppress);
      int VerifyUUIDIsWorkStore(const char *uuid);
      int NumberOfWorkStoreBlocksFromUUID(const char *filestoreid);
      int AddKeyDependency(const char *uuid, const char *keyname);
      int AddWorkStoreKeyDependency(const char *work_store, const char *sshkeyname);
      int AddComputeKeyDependency(const char *compute, const char *keyname);
      void CreateTablesIfNecessary();
};

#endif
